package collectionFramework.collectionsAndArrays;

import java.util.Collections;
import java.util.LinkedList;
import java.util.ListIterator;

class Employee implements Comparable<Employee> {
	private int id;
	private String name;
	private float salary;
	private LinkedList<Employee> ll = new LinkedList<Employee>();

	public Employee() {
	}

	public Employee(int id, String name, float salary) {
		this.id = id;
		this.name = name;
		this.salary = salary;
	}

	void display() {
		ListIterator<Employee> li = ll.listIterator();
		while (li.hasNext())
			System.out.println(li.next());
	}

	@Override
	public String toString() {
		return "ID=" + id + " Name=" + name + " Salary=" + salary;
	}

	@Override
	public int compareTo(Employee emp) {
		if (this.id > emp.id) return 1;
		return -1;
	}
}

public class MyCustomSort {

	public static void main(String[] args) {
		Employee emp0 = new Employee(1, "Raj", 16000);
		Employee emp1 = new Employee(3, "Ajay", 25600);
		Employee emp2 = new Employee(2, "Mohan", 17823);
		LinkedList<Employee> ll = new LinkedList<Employee>();

		ll.add(emp0);
		ll.add(emp1);
		ll.add(emp2);

		ListIterator<Employee> lit = ll.listIterator();
		System.out.println("Before Sort");
		while (lit.hasNext())
			System.out.println(lit.next());

		Collections.sort(ll);

		lit = ll.listIterator();
		System.out.println("After Sort");
		while (lit.hasNext())
			System.out.println(lit.next());
	}
}
